package paf.exporter;

import java.awt.Component;
import java.awt.Dimension;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.io.FileOutputStream;
import java.io.OutputStream;

import javax.imageio.ImageIO;

public class JPGFile implements FileInterface {

	protected JPGFile() {}
	
	/**
	 * @see paf.exporter/FileInterface.java
	 */
	@Override
	public void writeToFile(Component c, String fileName) {
		Dimension size = c.getSize();
		BufferedImage myImage = new BufferedImage(size.width, size.height, BufferedImage.TYPE_INT_RGB);
		Graphics2D g2 = myImage.createGraphics();
		c.paint(g2);
		try {
			OutputStream out = new FileOutputStream(fileName + ".jpg");
			ImageIO.write(myImage,"jpg",out);
			out.close();
		} catch (Exception e) {
			System.out.println(e); 
		}
	}
	
	@Override
	public String toString() {
		return "JPG File";
	}
}